from django.db import models
from Administrative_office_system.utils.BaseModel import BaseModel


class SupportSubsidies(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科主任审核'),
        ('two', '申请人分管院长'),
        ('three', '财务科分管院长'),
        ('refuse', '拒绝'),
        ('end', '结束'),
        ('stop', '终止'),
    )
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=False, null=False, on_delete=models.CASCADE)
    start_time = models.CharField(max_length=255, verbose_name='开始时间', default='')
    end_time = models.CharField(max_length=255, verbose_name='结束时间', default='')
    note = models.CharField(max_length=255, verbose_name='备注', default='')
    can_revise = models.CharField(max_length=10, verbose_name='是否可以修改', default='1')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='support_subsidies_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='support_subsidies_already_audit_users', blank=True)

    def get_state_str(self):
        if self.state == 'refuse':
            return '拒绝'
        elif self.state == 'end':
            return '结束'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class SupportSubsidiesRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科主任审核'),
        ('two', '申请人分管院长'),
        ('three', '财务科分管院长')
    )
    parent_id = models.ForeignKey('SupportSubsidies', verbose_name="体检科支援加班补助表", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')

    class Meta:
        managed = True
        verbose_name = '体检科支援加班补助表'
        verbose_name_plural = verbose_name